const PDFParser = require('pdf2json');
const Translator = require("./lib/translator")
const {appendFileSync }  = require("fs");
const src = './test.pdf';
 
var pdfParser = new PDFParser(this, 1);
pdfParser.loadPDF(src);
pdfParser.on('pdfParser_dataError', errData =>reject( new Error(errData.parserError)));
pdfParser.on('pdfParser_dataReady',async () => {
    let data = pdfParser.getRawTextContent();
    let translate= new Translator();
    translate.setConfig({
        from:'EN',
        to:'zh_CHS',
        appKey:'60835e17d1bdcdc6',
        secretKey:'Ov7roNtS5fY1mw60bGouSCUYgRAp9Gzy'
    })

    let strArr = data.split(/\./g);
    
    for(let i = 0;i<strArr.length;i++){
        let text = await translate.translateSync(strArr[i]);
        appendFileSync("English.txt",strArr[i])
        appendFileSync("Chinese.txt",text)
    }
});

